<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    button{
      background:yellow;
    }
    .classA{
      color:#f0f;
      background-color:#666;
    }
  </style>
</head>
<body>
  <div id='demo'>
   <h2>v-for遍历数组</h2>
   <ul>
     <li v-for='(item,index) in person' :key='item.id'>
       {{index}}--{{item.id}}--{{item.name}}--{{item.age}}
       <button @click='deleteP(index)'>删除</button>
       <button @click="updateP(index,{id:item.id,name:'xxxx',age:22})">更新</button>
     </li>
   </ul>
   <h2>v-for遍历对象</h2>
   <ul>
     <li v-for='(value,key) in person[2]' :key="key">
       {{key}}={{value}}
     </li>
   </ul>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    const vm = new Vue({
      el:'#demo',
      data:{
        person:[
          {id:1,name:'A',age:12},
          {id:2,name:'B',age:13},
          {id:3,name:'C',age:14},
          {id:4,name:'D',age:15},
        ],
      },
      methods:{
        deleteP(index){
          
          this.person.splice(index,1)
        },
        updateP(index,newP){
          this.person.splice(index,1,newP)
        }
      }
    })
  </script>
</body>
</html>